<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/17 0017
 * Time: 下午 3:57
 */
namespace app\member\model;
use think\console\command\make\Model;
use think\Db;

class Member extends Model{
    public function mem_add($data){
        $add = Db::name('member')->insertGetId($data);
        return $add;
    }
    public function login($data){
        $info = Db::name('member')
            ->where(['username'=>$data['username'],'del'=>1])
            ->find();
        return $info;
    }
    public function mem_info($data){
        $info = Db::name('member')->where(['id'=>$data['id']])->find();
        return $info;
    }
    public function mem_update($data){
        $id = $data['id'];
        unset($data['id']);
        $up = Db::name('member')
            ->where(['id'=>$id])->update($data);
        return $up;
    }
    public function mem_list($data){
        #条件
        $where = 'del=1';
        $where.= isset($data['keyword'])? ' and CONCAT(username) like "%'.$data['keyword'].'%"':'';
        $where.= isset($data['identity'])? ' and identity='.$data['identity'].'%"':'';
        #总条数
        $total = Db::name('member')->where($where)->count();
        #总页数
        $page = ceil($total/$data['limits']);
        if ($data['curr']>$page){
            $data['curr']=$page;
        }
        #列表
        $list = Db::name('member')->where($where)->page($data['curr'],$data['limits'])->select();
        #返回值
        $result = [
            'list'  =>$list,
            'page'  =>$page,
            'limits'=>$data['limits'],
            'total' =>$total,
            'curr'  =>$data['curr']
        ];
        return $result;
    }
}